package com.wjh.feign.impl;

import com.alibaba.fastjson2.JSON;
import com.wjh.base.ResponseApiData;
import com.wjh.order.dto.OrderDetailDto;
import com.wjh.order.request.UpdateOrderPayStateRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import com.wjh.feign.IOrderFeignClient;
import org.springframework.stereotype.Component;

/**
 * 订单服务容错/熔断处理
 * 
 * @author wenjianhai
 * @date 2023/6/26
 * @since JDK 17
 */
@Slf4j
@Component
public class OrderFeignClientImpl implements FallbackFactory<IOrderFeignClient> {
    @Override
    public IOrderFeignClient create(Throwable cause) {
        return new IOrderFeignClient() {
            /**
             * 查询订单及其详情
             *
             * @param orderGuid 订单Guid
             * @return ResponseApiData
             * @date 2023-06-26
             * @author wenjianhai
             * @since JDK 17
             */
            @Override
            public ResponseApiData<OrderDetailDto> queryOrderAndDetails(String orderGuid) {
                log.error("查询订单及其详情-失败.订单Guid:{}, 失败信息:{}", orderGuid, cause.getMessage());
                return ResponseApiData.systemFail("查询订单及其详情失败");
            }

            /**
             * 更新订单的支付状态
             *
             * @param request 请求参数
             * @return ResponseApiData
             * @date 2023-06-29
             * @author wenjianhai
             * @since JDK 17
             */
            @Override
            public ResponseApiData<?> updatePayState(UpdateOrderPayStateRequest request) {
                log.error("更新订单的支付状态-失败.请求参数:{}, 失败信息:{}", JSON.toJSONString(request), cause.getMessage());
                return ResponseApiData.systemFail("更新订单的支付状态失败");
            }
        };
    }
}
